import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;

public class Main {
	static JFrame frame= new JFrame("SmartHouse");
	static JLabel label = new JLabel("Sistem de recomandare pentru locuinte ");
	static JTextArea texta1 = new JTextArea(30, 30);
	static JTextArea texta = new JTextArea(30, 30);
	public static int n=16;	
	public static String ceva;
	
	public static void main(String[] args){
		
		frame.setVisible(true);
		frame.setSize(1000,800);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel(new GridBagLayout());
		frame.getContentPane().add(panel,BorderLayout.NORTH);
		GridBagConstraints c = new GridBagConstraints();
		
		c.insets= new Insets(10,10,10,10);
		c.gridx=1;
		c.gridy=0;
		panel.add(label,c);

		JButton button =new JButton("Seteaza preferintele");
		c.gridx=0;
		c.gridy=2;
		panel.add(button,c);
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				JFrame frame2=new JFrame("Preferinte");
				frame2.setVisible(true);
				frame2.setSize(400,400);
		
				JPanel panel2 = new JPanel(new GridBagLayout());
				frame2.getContentPane().add(panel2,BorderLayout.NORTH);
				GridBagConstraints d = new GridBagConstraints();
				
				JLabel label= new JLabel("Setarea Preferintelor:");
				d.gridx=0;
				d.gridy=0;
				d.insets= new Insets(10,10,10,10);
				panel2.add(label,d);
				
				final JLabel intrebare= new JLabel("Pentru cine setezi preferintele?");
				d.gridx=0;
				d.gridy=1;
				panel2.add(intrebare,d);
			    //Create the radio buttons.
			   final JRadioButton v1 = new JRadioButton("Ion");
			    v1.setMnemonic(KeyEvent.VK_B);
			    v1.setActionCommand("Ion");
			    v1.setSelected(true);
			    
			   final JRadioButton v2 = new JRadioButton("Alina");
			    v2.setMnemonic(KeyEvent.VK_C);
			    v2.setActionCommand("Alina");

			   final  JRadioButton v3 = new JRadioButton("Ana");
			    v3.setMnemonic(KeyEvent.VK_D);
			    v3.setActionCommand("Ana");

			  final  JRadioButton v4 = new JRadioButton("Vlad");
			    v4.setMnemonic(KeyEvent.VK_R);
			    v4.setActionCommand("Vlad");
			    
			    if(v1.isSelected()){
			    	ceva+="1.1 ";
			    }
			    if(v2.isSelected()){
			    	ceva+="1.2 ";
			    }
			    if(v3.isSelected()){
			    	ceva+="1.3 ";
			    }
			    if(v4.isSelected()){
			    	ceva+="1.4 ";
			    }
			    //Group the radio buttons.
		        ButtonGroup group = new ButtonGroup();
			    group.add(v1);
			    group.add(v2);
			    group.add(v3);
			    group.add(v4);

		        JPanel radioPanel = new JPanel(new GridLayout(0, 1 ));
		        radioPanel.add(v1);
	            radioPanel.add(v2);
		        radioPanel.add(v3);
		        radioPanel.add(v4);
		      
		        d.gridx=0;
		        d.gridy=3;
		        panel2.add(radioPanel, d);
			 	  
			    JButton button1 =new JButton("Next");
				d.gridx=0;
				d.gridy=4;
				panel2.add(button1,d);
		        
				button1.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
				
						if (n==16) {
						       intrebare.setText("La ce ora preferi sa te trezesti?");
						     
				                v1.setText("La ora 6:00");
				                v2.setText("La ora 7:00");
							    v3.setText("La ora 8:00");
							    v4.setText("La ora 9:00");
							    if(v1.isSelected()){
							    	ceva+="2.1 ";
							    }
							    if(v2.isSelected()){
							    	ceva+="2.2 ";
							    }
							    if(v3.isSelected()){
							    	ceva+="2.3 ";
							    }
							    if(v4.isSelected()){
							    	ceva+="2.4 ";
							    }							  
				        	}
		        	if (n==15) {
				       intrebare.setText("La ce ora preferi sa mananci?");
				     
		                v1.setText("La ora 12:00");
		                v2.setText("La ora 13:00");
					    v3.setText("La ora 14:00");
					    v4.setText("La ora 15:00");
					    if(v1.isSelected()){
					    	ceva+="3.1 ";
					    }
					    if(v2.isSelected()){
					    	ceva+="3.2 ";
					    }
					    if(v3.isSelected()){
					    	ceva+="3.3 ";
					    }
					    if(v4.isSelected()){
					    	ceva+="3.4 ";
					    }
					  
		        	}
		        	
		        	if (n==14) {
		        		intrebare.setText("La ce ora preferi sa dormi?");		 		       

		        		v1.setText("La ora 21:00");
		        		v2.setText("La ora 22:00");
		        		v3.setText ("La ora 22:30");
		        		v4.setText ("La ora 23:00");	
		        		
		        		if(v1.isSelected()){
					    	ceva+="4.1 ";
					    }
					    if(v2.isSelected()){
					    	ceva+="4.2 ";
					    }
					    if(v3.isSelected()){
					    	ceva+="4.3 ";
					    }
					    if(v4.isSelected()){
					    	ceva+="4.4 ";
					    }
		        	}
		        	
		        	if (n==13){
		        		intrebare.setText("La ce ora preferi sa speli la masina de spalat?");
		        		v1.setText("La ora 16:00");
		        		v2.setText("La ora 16:30");
		        		v3.setText("La ora 17:30");
		        		v4.setText("La ora 18:00");
		        		
		        		if(v1.isSelected()){
					    	ceva+="5.1 ";
					    }
					    if(v2.isSelected()){
					    	ceva+="5.2 ";
					    }
					    if(v3.isSelected()){
					    	ceva+="5.3 ";
					    }
					    if(v4.isSelected()){
					    	ceva+="5.4 ";
					    }
		        		
		        	}
		        	
		            if (n==12){
		            	intrebare.setText("La ce ora preferi sa aspiri?");
				    v1.setText("La ora 16:00");
				    v2.setText ("La ora 16:30");
				    v3.setText  ("La ora 17:30");
				    v4.setText  ("La ora 18:00");
				    if(v1.isSelected()){
				    	ceva+="6.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="6.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="6.3 ";
				    }
				    if(v4.isSelected()){
				    	ceva+="6.4 ";
				    }
		            }
		            
		            if (n==11){
		            	intrebare.setText   ("Unde vrei sa aspiri?");
				    v1.setText("In dormitor1.");
				    v2.setText ("In dormitor2.");
				    v3.setText  ("In dormitor3.");
				    v4.setText    ("In hol.");
				     
				    if(v1.isSelected()){
				    	ceva+="7.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="7.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="7.3 ";
				    }
				    if(v4.isSelected()){
				    	ceva+="7.4 ";
				    }
		            }
		            
		            if (n==10){
		            	intrebare.setText ("Unde preferi mergi dupa ce te trezesti?");				
					  
				    v1.setText ("Baie");
				    v2.setText  ("Bucatarie");
				    v3.setText ("Living");
				    v4.setVisible(false);
				
				    if(v1.isSelected()){
				    	ceva+="8.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="8.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="8.3 ";
				    }}
		            
		            if (n==9){
		            	intrebare.setText ("Esti in baie. Alege o actiune.");				
					  
				    v1.setText  ("Te speli?");
				    v2.setText  ("Folosesti toaleta? ");
				    v3.setVisible(false);
				    if(v1.isSelected()){
				    	ceva+="9.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="9.2 ";
				    }}
		            	            
		            if (n==8){
		            	intrebare.setText ("Esti in baie. Alege o actiune.");
				
					  
				    v1.setText  ("Te speli pe maini si pe fata?");
				    v2.setText    ("Faci dus?");
				    v3.setText     ("Te speli pe dinti?");
				    v3.setVisible(true);
				    if(v1.isSelected()){
				    	ceva+="10.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="10.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="10.3 ";
				    }			
		            }
		            
		            
		            if (n==7){
		            	intrebare.setText   ("Ai ales sa mergi in bucatarie. Ce actiune alegi?");

				    v1.setText        ("Vrei sa mananci?");
				    v2.setText    ("Vrei sa bei apa?");
				    v3.setVisible(false);
				    if(v1.isSelected()){
				    	ceva+="11.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="11.2 ";
				    }
			
		            }
		            
		            if (n==6){
		            	intrebare.setText    ("Ai ales sa mergi in bucatarie, sa mananci. Ce actiune alegi?");
      
				    v1.setText     ("Mananci de la frigider? ");
				    v2.setText    ("Gatesti?");
				    if(v1.isSelected()){
				    	ceva+="12.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="12.2 ";
				    }
				
				 
		            }
		            
		            if (n==5){
		            	intrebare.setText ("Ai ales sa mergi in bucatarie, sa mananci ceva cald. Ce actiune alegi?");
		      		   
				    v1.setText         ("Incalzesti la microunde? ");
				    v2.setText   	(" Gatesti la aragaz?"); 
				    v3.setText (" Folosesti SandwichMaker-ul?");
				    v3.setVisible(true);
				    if(v1.isSelected()){
				    	ceva+="13.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="13.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="13.3 ";
				    }
				
		            }
		            
		            
		            if (n==4){
		            	intrebare.setText  ("Ai ales sa mergi in living. Ce actiune alegi?");
	    
				    v1.setText              ("Te uiti la TV?");
				    v2.setText  	 (" Folosesti calculatorul?");
				    v3.setVisible(false);
				    if(v1.isSelected()){
				    	ceva+="14.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="14.2 ";
				    }
				
			
		            }
		            
		            if (n==3){
		            	intrebare.setText    ("Ai ales sa mergi in living si sa te uiti la Tv. Cat timp preferi sa te uiti la tv?");
				    v1.setText               ("30 minute");
				    v2.setText  	 	 (" o ora");
				    v3.setText 	   (" o ora si 30 minute");
				    v4.setText (" doua ore");
				    v3.setVisible(true);
				    v4.setVisible(true);
				    if(v1.isSelected()){
				    	ceva+="15.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="15.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="15.3 ";
				    }
				    if(v4.isSelected()){
				    	ceva+="15.4 ";
				    }
		            }
		            
		            if (n==2){
		            	intrebare.setText       ("Ai ales sa mergi in living si sa folosesti calculatorul. Cat timp preferi sa iti petreci utilizand calculatorul?");
		      		      v1.setText               ("30 minute");
				    v2.setText  	 	 (" o ora");
				    v3.setText 	   (" o ora si 30 minute");
				    v4.setText (" doua ore");
				    if(v1.isSelected()){
				    	ceva+="16.1 ";
				    }
				    if(v2.isSelected()){
				    	ceva+="16.2 ";
				    }
				    if(v3.isSelected()){
				    	ceva+="16.3 ";
				    }
				    if(v4.isSelected()){
				    	ceva+="16.4 ";
				    }
		            }
		        	n=n-1;
		        	
		        	if (n==0){
		        		System.out.println(ceva);
		        	}}			
					});	        
			}
		});
		
		JButton button1 =new JButton("Compileaza Scenariul");
		c.gridx=1;
		c.gridy=2;
		panel.add(button1,c);
		button1.addActionListener(new ActionListener(){
		   public void actionPerformed(ActionEvent e){
		      List<Propozitie> Persoane=new ArrayList<Propozitie>();
		      String pers="";
			  
		      try{
		    	  BufferedReader in=new BufferedReader(new FileReader("scenariu.txt"));
		    	  String line;
		    	  while((line=in.readLine())!= null){
		    		  if(line.startsWith("Creaza")){
		    			  pers = line.substring(7);
		    			  Propozitie randCitit=new Propozitie(pers,"","","","","","","","","");
		    			  Persoane.add(randCitit);
		    			  
		    		  }
		    		  }
		    	  for(Propozitie p: Persoane)
		    	      System.out.println(p.getPersoana());
		    	  }
		    	   catch (IOException exc){
		    		  System.err.println(exc);
		    	  }
		      }});
		
		JButton button2 =new JButton("Porneste Sistemul");
		c.gridx=2;
		c.gridy=2;
		panel.add(button2,c);
		button2.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){    
			 try{
				    FileInputStream fstream = new FileInputStream("Scenariu.txt");
				    DataInputStream in = new DataInputStream(fstream);
				    BufferedReader br = new BufferedReader(new InputStreamReader(in));
				    String strLine;
				    while ((strLine = br.readLine()) != null)   {		   
				      texta.append(strLine+"\n");
				    }				   
				    in.close();
				    }catch (Exception s){
				      System.err.println("Error: " + s.getMessage());
				    }
				  }
		});
		JLabel label2 = new JLabel("Actiunile persoanelor: ");
		c.gridx=0;
		c.gridy=3;
		panel.add(label2,c);
		
		texta.setEditable(false);
		c.gridx=0;
		c.gridy=4;
     	panel.add(texta,c);
     	
     	JLabel label3 = new JLabel("Actiunile sistemului: ");
		c.gridx=1;
		c.gridy=3;
		panel.add(label3,c);
		
		texta.setEditable(false);
		c.gridx=1;
		c.gridy=4;
		panel.add(texta1,c);
		
		JLabel label4=new JLabel("00:00:00");
		label4.setFont(new Font("Courier New", Font.BOLD,  18));
	    label4.setForeground(Color.GREEN);
		c.gridx=2;
		c.gridy=5;
		panel.add(label4,c);

	}//main
	}//Main
		


		

